home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / moush101.zip / TEST.CPP < prev    next >
C/C++ Source or Header  |  1992-07-27  |  2KB  |  112 lines

  1.  
  2. /****************************************************************************
  3.  
  4.       Mouse example program
  5.  
  6.     originally by Erik Kangas, in MMOUSE10.ZIP
  7.  
  8.     modified to use C++ encapsulation by Michael Chen, 7/24/1992
  9.     modified to use my own driver, 7/26/1992
  10.     modified to use check_() functions, 7/26/1992
  11.  
  12.     program draws random lines;
  13.     press either LMB or RMB to continue.
  14.  
  15.     drag with LMB to draw lines;
  16.     press RMB to quit.
  17.  
  18. ****************************************************************************/
  19.  
  20. #include <graphics.h>          // Mouse driver requires BGI graphics
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <time.h>
  24. #include "mouse.hpp"
  25. #include "bgi.hpp"
  26.  
  27. void main() {
  28.  
  29.     BGI Graphics;
  30.  
  31.     Mouse mouse;
  32.  
  33.     // Display default cursor.
  34.  
  35.     mouse.show();
  36.  
  37.  
  38.     // Draw random lines until either LMB or RMB released.
  39.  
  40.     randomize();
  41.  
  42.     mouse.update_region(0,0,getmaxx(),getmaxy());
  43.  
  44.     do
  45.     {
  46.         setcolor(random(getmaxcolor()+1));
  47.         line(random(getmaxx()+1),random(getmaxy()+1),
  48.              random(getmaxx()+1),random(getmaxy()+1));
  49.     } while (!(mouse.check_up(LEFT_BUTTON)
  50.         || mouse.check_up(RIGHT_BUTTON)));
  51.  
  52.     mouse.clear_all();    // Clear any pending button checks
  53.                 // and moved checks
  54.  
  55.     clearviewport();
  56.     mouse.show();
  57.  
  58.     // Start drawing lines by dragging with the LMB down; end with RMB.
  59.  
  60.     setcolor(WHITE);
  61.     int drag=0;
  62.     int x,y,x1,y1;
  63.  
  64.     do
  65.     {
  66.         mouse.status();
  67.  
  68.         if (mouse.check_down(LEFT_BUTTON))
  69.         {
  70.            mouse.hide();
  71.            x = x1 = mouse.x();        // Store position of cursor
  72.            y = y1 = mouse.y();
  73.            drag=1;
  74.            setwritemode(XOR_PUT);
  75.            line(x,y,x1,y1);
  76.            mouse.show();
  77.         };
  78.  
  79.  
  80.         if (mouse.check_up(LEFT_BUTTON))
  81.         {
  82.            mouse.hide();
  83.            line(x,y,x1,y1);
  84.            setwritemode(COPY_PUT);
  85.            line(x,y,mouse.x(),mouse.y());
  86.            mouse.show();
  87.            drag=0;
  88.         };
  89.  
  90.         if (drag
  91.         && ((mouse.x() != x1) || (mouse.y() != y1)))
  92.         {
  93.            mouse.hide();
  94.            setwritemode(XOR_PUT);
  95.            line (x,y,x1,y1);
  96.            x1 = mouse.x();
  97.            y1 = mouse.y();
  98.            line (x,y,x1,y1);
  99.            mouse.show();
  100.         };
  101.     }
  102.     while (!mouse.check_up(RIGHT_BUTTON));
  103.  
  104.  
  105.     // Exit graphics system (destructor for BGI)
  106.  
  107.  
  108.     // Destructor for Mouse mouse calls EndMouse when variable is out of scope
  109.  
  110. }
  111.  
  112.